﻿@using SmartStore.Core.Domain.Catalog;
@model OrderModel.AddOrderProductModel.ProductDetailsModel

@{
    ViewBag.Title = string.Format(T("Admin.Orders.Products.AddNew.Title2").Text, Model.Name, Model.OrderId);
}

<script type="text/javascript">
    $(function () {
		$('#ProductAddAttributeContainer').find('select').selectWrapper();
	});
</script>

@*we add enctype = "multipart/form-data" because "File upload" attribute control type requries it*@
@using (Html.BeginForm("AddProductToOrderDetails", "Order",
    new RouteValueDictionary(new { orderId = Model.OrderId, productId = Model.ProductId }),
    FormMethod.Post,
    new Dictionary<string, Object> { { "enctype", "multipart/form-data" } }))
{
    @Html.ValidationSummary(false)
    <div class="section-header">
        <div class="title">
            @string.Format(T("Admin.Orders.Products.AddNew.Title2").Text, Model.Name, Model.OrderId)
            @Html.ActionLink("(" + T("Admin.Orders.Products.AddNew.BackToList") + ")", "AddProductToOrder", new { orderId = Model.OrderId })
        </div>
        <div class="options">
        </div>
    </div>
    <div>
        @if (Model.Warnings.Count > 0)
        {
            <div class="alert alert-danger">
                @foreach (var warning in Model.Warnings)
                {
                    @warning
                    <br />
                }
            </div>
        }
    </div>

    if (Model.ProductType == ProductType.SimpleProduct)
    {
	    <table class="adminContent">
		    <tr>
			    <td class="adminTitle">
				    @Html.SmartLabelFor(model => model.UnitPriceInclTax)
			    </td>
			    <td class="adminData">
				    @Html.EditorFor(model => model.UnitPriceInclTax)
			    </td>
		    </tr>
		    <tr>
			    <td class="adminTitle">
				    @Html.SmartLabelFor(model => model.UnitPriceExclTax)
			    </td>
			    <td class="adminData">
				    @Html.EditorFor(model => model.UnitPriceExclTax)
			    </td>
		    </tr>
			<tr>
				<td class="adminTitle">
					@Html.SmartLabelFor(model => model.TaxRate)
				</td>
				<td class="adminData">
					@Html.EditorFor(model => model.TaxRate)
				</td>
			</tr>
		    <tr>
			    <td class="adminTitle">
				    @Html.SmartLabelFor(model => model.Quantity)
			    </td>
			    <td class="adminData">
				    @Html.EditorFor(model => model.Quantity)
			    </td>
		    </tr>
		    <tr>
			    <td class="adminTitle">
				    @Html.SmartLabelFor(model => model.SubTotalInclTax)
			    </td>
			    <td class="adminData">
				    @Html.EditorFor(model => model.SubTotalInclTax)
			    </td>
		    </tr>
		    <tr>
			    <td class="adminTitle">
				    @Html.SmartLabelFor(model => model.SubTotalExclTax)
			    </td>
			    <td class="adminData">
				    @Html.EditorFor(model => model.SubTotalExclTax)
			    </td>
		    </tr>
		</table>
		    
        <div id="ProductAddAttributeContainer">
            @{ Html.RenderPartial("_ProductAddAttributes", Model); }
        </div>
		
		var dataDictGiftCard = new ViewDataDictionary();
		dataDictGiftCard.TemplateInfo.HtmlFieldPrefix = Model.GiftCardFieldPrefix;
        @Html.Partial("_ProductAddGiftCardInfo", Model.GiftCard, dataDictGiftCard)
            
		<table class="adminContent">
			<tr>
				<td class="adminTitle">
					@Html.SmartLabelFor(model => model.AdjustInventory)
				</td>
				<td class="adminData">
					@Html.EditorFor(model => model.AdjustInventory)
					@Html.ValidationMessageFor(model => model.AdjustInventory)
				</td>
			</tr>
			@if(Model.ShowUpdateTotals)
			{
				<tr>
					<td class="adminTitle">
						@Html.SmartLabelFor(model => model.UpdateTotals)
					</td>
					<td class="adminData">
						@Html.EditorFor(model => model.UpdateTotals)
						@Html.ValidationMessageFor(model => model.UpdateTotals)
					</td>
				</tr>
			}
			<tr>
				<td class="adminTitle"></td>
				<td class="adminData">
					<button type="submit" class="btn btn-primary">
						<i class="fa fa-plus"></i>
						<span>@T("Admin.Orders.Products.AddNew")</span>
					</button>
				</td>
			</tr>
		</table>
    }
    else if (Model.ProductType == ProductType.GroupedProduct)
    {
        <div>
            Grouped products are not currently supported for adding to an existing order.
        </div>
    }
    else if (Model.ProductType == ProductType.BundledProduct)
    {
        <div>
            Bundled products are not currently supported for adding to an existing order.
        </div>
    }
}